package com.htfyun.roobofactory.engineerTest;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.TextView;

import com.htfyun.roobofactory.R;
import com.viewpagerindicator.TabPageIndicator;

/**
 * Created by sst on 2018/7/11.
 */

public class EngineerTestMainActivity extends FragmentActivity {

    private final static String TAG = "EngineerTestMainActivity";
    private Context mContext;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        View decorView = getWindow().getDecorView();
        int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION  // hide naviagtion,and whow again when touch
//                      | View.SYSTEM_UI_FLAG_IMMERSIVE    // use with SYSTEM_UI_FLAG_HIDE_NAVIGATION.only show when wipe
                // top or bottom of screen.
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY // the same with SYSTEM_UI_FLAG_IMMERSIVE,but hide navigation
                // after a short timeout.
                // implements at frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
                | View.SYSTEM_UI_FLAG_FULLSCREEN;
//                | View.SYSTEM_UI_FLAG_LOW_PROFILE;
        decorView.setSystemUiVisibility(uiOptions);

        getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);


        setContentView(R.layout.activity_engineer_test);

        mContext = this;

        findViewById(R.id.txtReturn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Animation animation = AnimationUtils.loadAnimation(mContext, R.anim.anim_view_click);
                v.startAnimation(animation);

                finish();
            }
        });

        FragmentPagerAdapter adapter = new EngineerTestPagerAdapter(getSupportFragmentManager());

        ViewPager pager = (ViewPager) findViewById(R.id.pager);
        pager.setAdapter(adapter);

        TabPageIndicator indicator = (TabPageIndicator) findViewById(R.id.indicator);
        indicator.setViewPager(pager);
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.e(TAG, "destory = " + this);
    }

    private final class EngineerTestPagerAdapter extends FragmentPagerAdapter {
        public EngineerTestPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            Class<? extends Fragment> cls = EngineerItemsEnum.values()[position].getFragmentClass();
            try {
                return cls.newInstance();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return TestFragment.newInstance("Error cls = " + cls);
        }

        @Override
        public CharSequence getPageTitle(int position) {
            int resId = EngineerItemsEnum.values()[position].getNameResId();
            return getString(resId);
        }

        @Override
        public int getCount() {
            return EngineerItemsEnum.values().length;
        }
    }


}
